// @FileName  :h5t4.c
// @Time      :2024/4/25 18:53
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>
# include <ctype.h>

typedef struct node {
    int num, lid, rid;
    char word[64];
} node;
char line[1024], *p, word[64];
node tree[1024];
int size;

void make(int par, char *word) {
    if (tree[par].num == 0) {
        tree[par].num++;
        strcpy(tree[par].word, word);
        return;
    }
    int cmp = strcmp(tree[par].word, word);
    if (cmp == 0) {
        tree[par].num++;
        return;
    } else if (cmp > 0) {
        if (tree[par].lid == 0)tree[par].lid = ++size;
        make(tree[par].lid, word);
        return;
    } else {
        if (tree[par].rid == 0)tree[par].rid = ++size;
        make(tree[par].rid, word);
        return;
    }
}

void print(node n) {
    if (n.lid)print(tree[n.lid]);
    printf("%s %d\n", n.word, n.num);
    if (n.rid)print(tree[n.rid]);
}

int main() {
    freopen("article.txt", "r", stdin);
    while (gets(line) != NULL) {
        for (int i = 0; i < strlen(line); i++) {
            if (isupper(line[i]))line[i] = tolower(line[i]);
            else if (islower(line[i])) continue;
            else line[i] = ' ';
        }
        p = line;
        while (sscanf(p, "%s", word) != EOF) {
            p = strstr(p, word) + strlen(word);
            make(0, word);
        }
    }
    printf("%s %s ", tree[0].word, tree[tree[0].rid].word);
    if (tree[tree[0].rid].rid != 0) {
        printf("%s", tree[tree[tree[0].rid].rid].word);
    }
    printf("\n");
    print(tree[0]);
}